﻿namespace WLFramework.IoC
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    /// <summary>
    /// IoC依赖注入容器接口
    /// </summary>
    public interface IIocContainer
    {
        /// <summary>
        /// 注册依赖对象的类型的创建函数，标记名称
        /// </summary>
        /// <typeparam name="T">要实现的类型</typeparam>
        /// <param name="creation">需要实现的类型的创建函数</param>
        /// <param name="label">标记名称</param>
        void Register<T>(Func<IIocContainer, T> creation, string label = "");

        /// <summary>
        /// 获取类型实现后的对象
        /// </summary>
        /// <typeparam name="T">需要实现的类型</typeparam>
        /// <param name="label">标记名称</param>
        /// <returns>实现后的对象</returns>
        T Resolve<T>(string label = "");

        /// <summary>
        /// 获取类型实现后的对象
        /// </summary>
        /// <typeparam name="T">需要实现的类型</typeparam>
        /// <param name="createNew">是否创建新的对象</param>
        /// <param name="label">标记名称</param>
        /// <returns>实现后的对象</returns>
        T Resolve<T>(bool createNew, string label = "");

        /// <summary>
        /// 检查容器是否包含指定的类型实现
        /// </summary>
        /// <typeparam name="T">需要实现的类型</typeparam>
        /// <param name="label">标记名称</param>
        /// <returns>true or false</returns>
        bool CanResolve<T>(string label = "");

        /// <summary>
        /// 获取类型实现后的对象
        /// </summary>
        /// <typeparam name="T">需要实现的类型</typeparam>
        /// <param name="instance">输出实现后的对象</param>
        /// <param name="label">标记名称</param>
        /// <returns>执行结果(true or false)</returns>
        bool TryResolve<T>(out T instance, string label = "");

        /// <summary>
        /// 获取类型实现后的对象
        /// </summary>
        /// <typeparam name="T">需要实现的类型</typeparam>
        /// <param name="instance">输出实现后的对象</param>
        /// <param name="createNew">是否创建新的对象</param>
        /// <param name="label">标记名称</param>
        /// <returns>执行结果(true or false)</returns>
        bool TryResolve<T>(out T instance, bool createNew, string label = "");

        /// <summary>
        /// 取消注册的依赖对象类型
        /// </summary>
        /// <typeparam name="T">需要取消的类型</typeparam>
        /// <param name="label">标记名称</param>
        /// <returns>执行结果(true or false)</returns>
        bool Unregister<T>(string label = "");

        /// <summary>
        /// 销毁已经创建的类型的实例
        /// </summary>
        /// <typeparam name="T">需要销毁的类型</typeparam>
        /// <param name="label">标记名称</param>
        /// <returns>执行结果(true or false)</returns>
        bool Destroy<T>(string label = "");
    }
}
